/*
 * @Descripttion:
 * @version:
 * @Author: liyuhang
 * @Date: 2022-05-19 10:27:55
 */

Vue.component("search-page", {
  template:
    '\
      <div class="search_wrapper" style="height: 100%; display: flex;flex-direction: column;">\
        <div class="bgcDiv1">\
          <van-search ref="search" shape="round" v-model="value1" placeholder="输入你想查找的内容" @focus="onFocus" @search="onSearch"/>\
        </div>\
        <div class="current">\
          <van-tabs v-model="active1" @click="onClick">\
            <van-tab title="新闻资讯">\
              <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getList(0)">\
                <van-cell v-for="item in currentContact" :key="item.id">\
                      <div class="wrpper">\
                        <div class="text_h">\
                          <div class="List_titleT">{{ item.fileName | textNum }}</div>\
                          <div class="List_wrapperT">\
                            <div class="List_time"><span>{{item.createTime}}</span><span class="lines">𐊊</span></div>\
                            <div class="List_access">{{ item.sizeByte }}</div>\
                            <div class="List_access">𐊊</div>\
                            <div class="List_access">来自{{ item.source | textNum2}}</div>\
                          </div>\
                        </div>\
                        <div class="omit">\
                            <el-dropdown @command="handleCommand($event,item)" trigger="click">\
                              <span class="el-dropdown-link">\
                                <div class="omit_box">\
                                  <img src="../image/dian.png" alt="">\
                                </div>\
                              </span>\
                              <el-dropdown-menu slot="dropdown">\
                                <el-dropdown-item command="a">编辑</el-dropdown-item>\
                                <el-dropdown-item command="b">删除</el-dropdown-item>\
                              </el-dropdown-menu>\
                            </el-dropdown>\
                        </div>\
                      </div>\
                </van-cell>\
              </van-list>\
            </van-tab>\
            <van-tab title="共享文档">\
              <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getList(0)">\
                  <van-cell v-for="item in list" :key="item.id">\
                      <div class="wrpper">\
                          <div class="img_box">\
                          <img src="../image/newDocument.png" alt="">\
                          </div>\
                          <div class="text_h">\
                              <div class="List_title">{{ item.fileName | textNum }}</div>\
                              <div class="List_wrapper">\
                                  <div class="List_time"><span>{{item.createTime}}</span><span class="lines">𐊊</span></div>\
                                  <div class="List_access">{{ item.sizeByte }}</div>\
                                  <div class="List_access">𐊊</div>\
                                  <div class="List_access">来自{{ item.source | textNum2}}</div>\
                              </div>\
                          </div>\
                          <div class="omit">\
                              <el-dropdown @command="handleCommand($event,item)" trigger="click">\
                                  <span class="el-dropdown-link">\
                                      <div class="omit_box">\
                                      <img src="../image/dian.png" alt="">\
                                      </div>\
                                  </span>\
                                  <el-dropdown-menu slot="dropdown">\
                                    <el-dropdown-item command="a">编辑</el-dropdown-item>\
                                    <el-dropdown-item command="b">删除</el-dropdown-item>\
                                  </el-dropdown-menu>\
                              </el-dropdown>\
                          </div>\
                      </div>\
                  </van-cell>\
              </van-list>\
            </van-tab>\
            <van-tab title="我的文档">\
              <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getList(0)">\
                <van-cell v-for="item in list" :key="item.id">\
                    <div class="wrpper">\
                        <div class="img_box">\
                          <img v-if=\'item.documentType == "Word"\' src="../image/newDocument.png" alt="">\
                          <img v-if=\'item.documentType == "Excel"\' src="../image/newDocument1.png" alt="">\
                          <img v-if=\'item.documentType == "PPT"\' src="../image/newDocument4.png" alt="">\
                          <img v-if=\'item.documentType == "PDF"\' src="../image/newDocument3.png" alt="">\
                        </div>\
                        <div class="text_h">\
                            <div class="List_title">{{ item.documentName }}</div>\
                            <div class="List_wrapper">\
                                <div class="List_time"><span>{{item.createTime}}</span><span class="lines">𐊊</span></div>\
                                <div class="List_access">{{ item.fileSize }}</div>\
                                <div class="List_access">𐊊</div>\
                                <div class="List_access">来自{{ item.source | textNum2}}</div>\
                            </div>\
                        </div>\
                        <div class="omit">\
                            <el-dropdown @command="handleCommand($event,item)" trigger="click">\
                                <span class="el-dropdown-link">\
                                    <div class="omit_box">\
                                    <img src="../image/dian.png" alt="">\
                                    </div>\
                                </span>\
                                <el-dropdown-menu slot="dropdown">\
                                    <el-dropdown-item command="a">编辑</el-dropdown-item>\
                                    <el-dropdown-item command="b">删除</el-dropdown-item>\
                                </el-dropdown-menu>\
                            </el-dropdown>\
                        </div>\
                    </div>\
                </van-cell>\
              </van-list>\
            </van-tab>\
          </van-tabs>\
        </div>\
      </div>\
          ',
  data() {
    return {
      active1: '',
      value1: '',
      list: [
        {
          fileName: '写页面测试假数据',
          source: '写页面测试假数据',
          sizeByte: '1.2Mb',
          createTime: '2021-12-12 12:12:12'
        }, {
          fileName: '写页面测试假数据',
          source: '写页面测试假数据',
          sizeByte: '1.2Mb',
          createTime: '2021-12-12 12:12:12'
        }
      ],
      value: 1,
      loading: false,
      finished: true,
      currentContact: [
        {
          fileName: '写页面测试假数据',
          source: '写页面测试假数据',
          sizeByte: '1.2Mb',
          createTime: '2021-12-12 12:12:12'
        },
      ],
      num: 0,
    };
  },
  filters: {
    textNum: (value) => {
      if (!value) return "";
      let data = value.split("");
      if (data.length < 15) {
        return value;
      }
      return value.slice(0, 15) + "...";
    },
    textNum1: (value) => {
      if (!value) return "";
      let data = value.split("");
      if (data.length < 10) {
        return value;
      }
      return value.slice(0, 10) + "...";
    },
    textNum2: (value) => {
      if (!value) return "";
      let data = value.split("");
      if (data.length < 5) {
        return value;
      }
      return value.slice(0, 5) + "...";
    },
  },
  created() {
    // this.getList(0)
    
  },
  mounted() {
    console.log(this.searchValue,179);
    if(this.searchValue){
      this.$refs.search.focus()
    }
  },
  props: ['searchValue'],
  methods: {
    //tab切换
    onClick(name, title) {
      console.log(name, title, 180);
      this.list = []
      if (title == '我的文档') {
        this.getList(0, '')
      }
    },
    getList(num, name) {
      const documentType = ''
      userId = sessionStorage.getItem("userId");
      if (sessionStorage.getItem("iscp_port")) {
        iscp_port = sessionStorage.getItem("iscp_port");
      } else {
        iscp_port = "";
      }
      this.num += 1
      let timestamp = new Date().getTime() + "";
      let data = {
        timestamp: timestamp,
        userId: userId,
        pageNum: this.num,
        documentType: name,
        documentSuffix: '',
      };
      console.log(data, 200);
      data = JSON.stringify(data);
      let sign = sm3(data);
      let AuthenticationSession = sessionStorage.getItem("Authentication");
      let URL = ''
      $.ajax({
        url: localUrlLink + iscp_port + '/document/record/getDocumentList',
        type: "post",
        async: false, //是否同步，false表示同步请求
        dataType: "json",
        data: data,
        headers: {
          "Content-Type": "application/json;charset=UTF-8",
          Authentication: AuthenticationSession,
          sign: sign,
          timestamp: timestamp
        },
        success: (res, txt, xhr) => {
          console.log(res, "res")
          $(".curtain").css("display", "none");
          if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
            let Authentication = xhr.getResponseHeader("Authentication")
            if (res.code == 200) {
              console.log(Authentication, 'Authentication')
              // if (Authentication) {
              console.log(888)
              sessionStorage.setItem("Authentication", Authentication);
              this.total = res.resultValue.total
              if (this.total == 0) {
                this.finished = true;
              }
              if (res.resultValue.list.length < 10) {
                this.finished = true;
              }
              if (this.num == 1) {
                console.log(532, this.num)
                this.list = []
                // this.tabulation = []
              }
              console.log(535, this.num)
              console.log(res.resultValue.list, 235);
              res.resultValue.list.forEach((item) => {
                this.list.push(item)
                // this.tabulation.push(item)
              })
              // 加载状态结束
              this.loading = false;
              if (this.list.length >= res.resultValue.total) {
                this.finished = true;
              }
              console.log(this.list, 241);
            } else if (res.code == 500) {
              mui.toast(res.resultValue, {
                duration: 1000,
                type: 'div'
              })
            } else {
              mui.toast('失败', {
                duration: 1000,
                type: 'div'
              })
            }
          } else {
            mui.toast('完整性校验失败', {
              duration: 1000,
              type: 'div'
            })
          }
        },
        error: (e) => {
          $(".curtain").css("display", "none");
          mui.toast('请求异常,请稍后再试', {
            duration: 1000,
            type: 'div'
          })
        },
      });
    },
    // 搜索
    onSearch(val) {
      console.log(val);
    },
    onFocus(){
      console.log(123);
    }
  },
});
